package org.nstack.header.volume;

import org.nstack.header.message.APIEvent;
import org.nstack.header.storage.snapshot.VolumeSnapshotInventory;
import org.nstack.header.rest.RestResponse;
import org.nstack.utils.data.SizeUnit;

import java.sql.Timestamp;


@RestResponse(allTo = "inventory")
public class APICreateVolumeSnapshotEvent extends APIEvent {

    private VolumeSnapshotInventory inventory;

    public APICreateVolumeSnapshotEvent(String apiId) {
        super(apiId);
    }

    public APICreateVolumeSnapshotEvent() {
        super(null);
    }

    public VolumeSnapshotInventory getInventory() {
        return inventory;
    }

    public void setInventory(VolumeSnapshotInventory inventory) {
        this.inventory = inventory;
    }
 
    public static APICreateVolumeSnapshotEvent __example__() {
        APICreateVolumeSnapshotEvent event = new APICreateVolumeSnapshotEvent();
        String volumeUuid= uuid();
        String snapshotUuid = uuid();
        VolumeSnapshotInventory inv = new VolumeSnapshotInventory();
        inv.setName("Snapshot-1");
        inv.setCreateDate(new Timestamp(System.currentTimeMillis()));
        inv.setLastOpDate(new Timestamp(System.currentTimeMillis()));
        inv.setParentUuid(uuid());
        inv.setDescription("create-snapshot-from-volume");
        inv.setState("Enabled");
        inv.setType("Hypervisor");
        inv.setVolumeUuid(volumeUuid);
        inv.setFormat("qcow2");
        inv.setUuid(snapshotUuid);
        inv.setStatus("Ready");
        inv.setPrimaryStorageUuid(uuid());
        inv.setPrimaryStorageInstallPath(String.format("/ nstack_ps/rootVolumes/acct-36c27e8ff05c4780bf6d2fa65700f22e/vol-%s/snapshots/%s.qcow2", volumeUuid, snapshotUuid));
        inv.setLatest(true);
        inv.setSize(SizeUnit.GIGABYTE.toByte(1));
        inv.setVolumeType(VolumeType.Root.toString());
        inv.setTreeUuid(uuid());

        event.setInventory(inv);

        return event;
    }

}
